// createContext 相当于创建 vue的provide,将组件的属性或方法共享给后代组件
import React, {createContext, useState} from 'react';

import Text21 from './test21';    
import Text22 from './test22';

export const AppContext = createContext();
const { Provider } = AppContext;


const Store = (props)=>{
    const [demoList, setDemoList] = useState([
        {
            name: 'xiaoming',
            age: 18
        },
        {
            name: 'xiaogang',
            age: 21
        },
    ]);

    const logTest= ()=>{
        console.log('父组件的方法');
    }

    return <div>
        <Provider value={ {demoList, setDemoList, logTest} }>
            {props.children}
        </Provider>
    </div>
}

const Test2 = ()=> {
    return <Store>
        <Text21/>
        <Text22/>
    </Store>
}
export default Test2;

